package com.neusoft.neuiotms.dcom.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@org.hibernate.annotations.Table(appliesTo = "neuiot_team_group", comment = "班组表")
@Table(name = "neuiot_team_group")
public class TeamGroup extends AbstractModel {

    private static final long serialVersionUID = 1L;

    /** 班组名称 */
    @NotBlank(message = "班组名称不能为空")
    @Length(max = 255, message = "班组名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '班组名称'")
    private String name;

    /** 组织名称 */
    @NotBlank(message = "组织名称不能为空")
    @Length(max = 255, message = "组织名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '组织名称'")
    private String orgName;

    /** 组织代码 */
    @NotBlank(message = "组织代码不能为空")
    @Length(max = 255, message = "组织代码不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String orgCode;

    /** 颜色 */
    @NotBlank(message = "颜色不能为空")
    @Column(length = 255, nullable = false)
    private String color;

    /** 关联职能 */
    @ManyToOne
    private FunctionalGroup functionalGroup;

    /** 关联人员 */
    @OneToMany(mappedBy = "group", fetch = FetchType.LAZY)
    @Cascade({CascadeType.ALL })
    private List<TeamUser> users = new ArrayList<>();
}
